<template>
  <el-upload class="upload-demo" drag :action="url" :auto-upload="false" :data="data" ref="uploadRef" :on-success="successUpload" :headers="{Token:token}">
    <el-icon class="el-icon--upload">
      <upload-filled />
    </el-icon>
    <div class="el-upload__text">文件拖到此处上传</div>
    <div class="join" @click="saveTrainLog" >上传文件</div>
    <div style="margin-top: 20px">
      只支持特定文件格式上传，请勿上传其他格式文件
    </div>
    <template #tip>
      <div class="el-upload__tip">上传文件大小请小于500kb</div>
    </template>
  </el-upload>
  <el-button class="ml-3" type="success" @click="submitUpload">
      确认提交
    </el-button>
</template>

<script setup >
import { UploadFilled } from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";
import {ref} from 'vue'

const token=localStorage.getItem('accessToken')
const props = defineProps({
  message: String,
  url: String,
  data: Object,
  context: Object
})
const { message, url, data,context } = props
const uploadRef = ref ()
const submitUpload = () => {
  uploadRef.value.submit()
}
const successUpload=()=>{
  ElMessage({
      message:props.message,
      type: "success",
    });
  if(context){
    context.value=false
  }
}
</script>

<style scoped>

</style>